package com.ruoyi.yyq.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.yyq.domain.CarGasStationType;
import com.ruoyi.yyq.service.ICarGasStationTypeService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 加油站和汽油种类中间Controller
 * 
 * @author ruoyi
 * @date 2025-05-12
 */
@RestController
@RequestMapping("/gasStationType")
@CrossOrigin
public class CarGasStationTypeController extends BaseController
{
    @Autowired
    private ICarGasStationTypeService carGasStationTypeService;

    /**
     * 查询加油站和汽油种类中间列表
     */
    @RequiresPermissions("yyq:gasStationType:list")
    @GetMapping("/list")
    public TableDataInfo list(CarGasStationType carGasStationType)
    {
        startPage();
        List<CarGasStationType> list = carGasStationTypeService.selectCarGasStationTypeList(carGasStationType);
        return getDataTable(list);
    }

    /**
     * 导出加油站和汽油种类中间列表
     */
    @RequiresPermissions("yyq:gasStationType:export")
    @Log(title = "加油站和汽油种类中间", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarGasStationType carGasStationType)
    {
        List<CarGasStationType> list = carGasStationTypeService.selectCarGasStationTypeList(carGasStationType);
        ExcelUtil<CarGasStationType> util = new ExcelUtil<CarGasStationType>(CarGasStationType.class);
        util.exportExcel(response, list, "加油站和汽油种类中间数据");
    }

    /**
     * 获取加油站和汽油种类中间详细信息
     */
    @RequiresPermissions("yyq:gasStationType:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(carGasStationTypeService.selectCarGasStationTypeById(id));
    }

    /**
     * 新增加油站和汽油种类中间
     */
    @RequiresPermissions("yyq:gasStationType:add")
    @Log(title = "加油站和汽油种类中间", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarGasStationType carGasStationType)
    {
        return toAjax(carGasStationTypeService.insertCarGasStationType(carGasStationType));
    }

    /**
     * 修改加油站和汽油种类中间
     */
    @RequiresPermissions("yyq:gasStationType:edit")
    @Log(title = "加油站和汽油种类中间", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarGasStationType carGasStationType)
    {
        return toAjax(carGasStationTypeService.updateCarGasStationType(carGasStationType));
    }

    /**
     * 删除加油站和汽油种类中间
     */
    @RequiresPermissions("yyq:gasStationType:remove")
    @Log(title = "加油站和汽油种类中间", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(carGasStationTypeService.deleteCarGasStationTypeByIds(ids));
    }

    /**
     * 根据加油站ID和汽油种类ID查询价格
     */
//    @RequiresPermissions("yyq:gasStationType:list")
    @GetMapping("/getPrice")
    public AjaxResult getPriceByStationAndType(
            @RequestParam Long gasStationId,
            @RequestParam Long gasTypeId) {
        Double price = carGasStationTypeService.selectPriceByStationAndType(gasStationId, gasTypeId);
        if (price == null) {
            return AjaxResult.error("未找到对应的价格信息");
        }
        return AjaxResult.success(price);
    }
}
